package com.xkdx.guangguang.wiget;

import android.content.Context;
import android.support.v4.app.FragmentManager;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.ListView;

import com.xkdx.guangguang.HomeActivity;
import com.xkdx.guangguang.fragment.home.HomeFragment;

public class CustomListView extends ListView {

	public static String TAG = "CustomListView";
	public boolean disableTouch = false;
	private HomeActivity demo;
	FragmentManager fm;
	HomeFragment homeFragment;

	public CustomListView(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
		// TODO Auto-generated constructor stub
	}

	public CustomListView(Context context, AttributeSet attrs) {
		super(context, attrs);
		this.demo = (HomeActivity) context;
		FragmentManager fm = demo.getSupportFragmentManager();
		homeFragment = (HomeFragment) fm.findFragmentByTag("homeFragment");
		
		
	}

	public CustomListView(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}

	@Override
	public boolean onTouchEvent(MotionEvent ev) {
		
		// TODO Auto-generated method stub
		int i = MotionEvent.ACTION_MOVE;
		int j = MotionEvent.ACTION_UP;
		int k = MotionEvent.ACTION_DOWN;
		int m = MotionEvent.ACTION_CANCEL;

		if (ev.getAction() == 0) {
			homeFragment.startTouch(this);
		}
		if (ev.getAction() == 3 && ev.getHistorySize() == 0) {
			homeFragment.startTouch(this);
		}
		if (ev.getAction() == 1) {
			
			homeFragment.handleFling(this);
		}

		return super.onTouchEvent(ev);
	}

	public void startTouch() {
		homeFragment.startTouch(this);
	}

}
